﻿DECLARE @Var_SpelCode VARCHAR(100)

SET @Var_SpelCode = @SpelCode_In

SELECT CODE AS ItemId,
       NAME AS ItemName,
       KMCODE AS ItemType,
       KMNAME AS ItemTypeName,
       UNITNAME AS ItemUnit,
       PRICE AS ItemPrice
FROM dbo.CHECKCODE(NOLOCK)
WHERE PYM LIKE @Var_SpelCode
AND DELDATE IS NULL
UNION ALL
SELECT a.A01 AS ItemId,
       a.A02 AS ItemName,
       b.A22 AS ItemType,
       b.A23 AS ItemTypeName,
       a.A06 AS ItemUnit,
       a.A08 AS ItemPrice
FROM YFSTORE a(NOLOCK)
JOIN dbo.GOODS b(NOLOCK) ON b.A01 = a.A01
WHERE a.A12 LIKE @Var_SpelCode
AND b.A22 NOT IN ('01','02','03')